package com.dtw.ditouwang.ui.mine;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;

import com.dtw.ditouwang.R;
import com.dtw.ditouwang.beans.NotifyBean;
import com.dtw.ditouwang.repositories.UserRepository;
import com.dtw.ditouwang.ui.BaseActivity;

import java.util.ArrayList;
import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

public class SystemNotifyActivity extends BaseActivity {
    SystemNotifyAdapter systemNotifyAdapter;
    List<NotifyBean.DataBean> notifyBeanList = new ArrayList<>();

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_notify_system);
        enableBack();
        setTitle("系统通知");
        RecyclerView recyclerView = findViewById(R.id.recyclerview);
        systemNotifyAdapter = new SystemNotifyAdapter(notifyBeanList);
        recyclerView.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, true));
        recyclerView.setAdapter(systemNotifyAdapter);

        webApi.getNotify(UserRepository.getInstance().getUserID(), 2).enqueue(new Callback<NotifyBean>() {
            @Override
            public void onResponse(Call<NotifyBean> call, Response<NotifyBean> response) {
                if (response.body().isResult()) {
                    notifyBeanList.clear();
                    notifyBeanList.addAll(response.body().getData());
                    systemNotifyAdapter.notifyDataSetChanged();
                }
            }

            @Override
            public void onFailure(Call<NotifyBean> call, Throwable t) {

            }
        });
    }
}
